import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * Description: ArrayList的学习
 */

class Student implements Comparable<Student>{
    private String name;
    private int age;
    private double score;

    public Student(String name, int age, double score) {
        this.name = name;
        this.age = age;
        this.score = score;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", score=" + score +
                '}';
    }

    @Override
    public int compareTo(Student o) {
        return (int) (this.score - o.score);
    }
}

public class Test {

    public static void main(String[] args) {
        String s1 = new String("welcome to bit");
        String s2 = new String("come");
        int length = s1.length();
        List<Character> list = new ArrayList<>();
        for(int i = 0; i < length; i++) {
            if(s2.indexOf(s1.charAt(i)) == -1) {
                list.add(s1.charAt(i));
            }
        }
        for (Character c: list) {
            System.out.print(c);
        }
    }

    public static void main5(String[] args) {
        List<Student> list = new ArrayList<>();
        list.add(new Student("张三",20,90));
        list.add(new Student("李四",18,80));
        list.add(new Student("王五",30,70));
        for (Student x: list) {
            System.out.println(x);
        }
        System.out.println("==================");
        //操作集合类的工具类
        Collections.sort(list);
        for (Student s: list) {
            System.out.println(s);
        }
    }

    //数组的遍历
    public static void main4(String[] args) {
        List<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(5);
        int size = list.size();
        for (int i = 0; i < size; i++) {
            System.out.print(list.get(i) + " ");
        }
        System.out.println();
        for (Integer x: list) {
            System.out.print(x + " ");
        }
        System.out.println();
        System.out.print(list);
        System.out.println();
        Iterator<Integer> it1 = list.iterator();
        while(it1.hasNext()) {
            System.out.print(it1.next() + " ");
        }
        System.out.println();
        System.out.println("------------------");
        System.out.println("迭代器的remove操作：");
        Iterator<Integer> it = list.iterator();
        int i = 0;
        while ( it.hasNext() ) {
            Integer str = it.next();
            System.out.print(str + " ");
            it.remove();
        }
        /*Iterator<Integer> it2 = list.iterator();
        it2.remove();*/
        System.out.println(list);
    }

    public static void main3(String[] args) {
        List<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(5);
        System.out.println(list.indexOf(2));
        List<Integer> list1 = new ArrayList<>();
        list1.addAll(list);
        Integer[] arr = new Integer[10];
        Integer[] arr1 = list.toArray(arr);
        Object[] arr2 = list.toArray();
        for (Integer x: arr1) {
            System.out.print(x + " ");
        }
        /*System.out.println(list1);*/
    }
    public static void main2(String[] args) {
        //避免省略类型，否则：任意类型的元素都可以存放，使用时将是一场灾难
        //ArrayList创建，推荐写法
        //构造一个空的列表
        List<Integer> list = new ArrayList<>();

        //构造一个具有10个容量的列表
        List<Integer> list1 = new ArrayList<>(10);
        list1.add(1);
        list1.add(2);
    }
    public static void main1(String[] args) {
        ArrayList<Character> s = new ArrayList();
        String s1 = new String("welcome to bit");
        String s2 = new String("come");
        int j = 0;
        for (int i = 0; i < s1.length(); i++) {
            for (j = 0; j < s2.length(); j++) {
                if(s1.charAt(i) == s2.charAt(j)) {
                    break;
                }
            }
            if(j == s2.length()) {
                s.add(s1.charAt(i));
            }
        }
        System.out.println(s);
    }
}
